package com.cct.digitalarchapi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.cct.digitalarchapi.common.CommonUtil;
import com.cct.digitalarchapi.common.Response;
import com.cct.digitalarchapi.pojo.ArchCategory;
import com.cct.digitalarchapi.pojo.ArchDept;
import com.cct.digitalarchapi.service.ArchCategoryService;
import com.cct.digitalarchapi.service.ArchDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @FileName ArchDeptController
 * @Description 部门控制器
 * @Author Created by chenmingzhe
 * @Date 2023/11/25
 **/
@RestController
@RequestMapping(value = "/archDept")
public class ArchDeptController {
    @Autowired
    private ArchDeptService archDeptService;
    @Autowired
    private CommonUtil commonUtil;
    /**
     *获取所有的部门分类
     */
    @PostMapping
    @RequestMapping(value = "/getAllArchDept",method = RequestMethod.POST)
    public Response getAllArchDept(@RequestBody JSONObject obj){
        int pageNum=obj.getInteger("pageNum");
        int pageSize=obj.getInteger("pageSize");
        return  archDeptService.getAllArchDept(pageNum,pageSize);
    }
    /**
     * 新增部门分类
     */
    @PostMapping
    @RequestMapping(value = "/addArchDept",method = RequestMethod.POST)
    public Response addArchDept(@RequestBody ArchDept archDept){
        commonUtil.recordOperateLog("新增部门名称为"+archDept.getArchDeptName()+"的部门分类");
        return  archDeptService.addArchDept(archDept);
    }
    /**
     *删除一个部门分类
     */
    @PostMapping
    @RequestMapping(value = "/deleteArchDept",method = RequestMethod.POST)
    public Response deleteArchDept(@RequestBody JSONObject obj){
        int archDeptId = obj.getInteger("archDeptId");
        commonUtil.recordOperateLog("删除部门分类Id为"+archDeptId+"的部门分类");
        return  archDeptService.deleteArchDept(archDeptId);
    }

    /**
     * 修改一个部门分类,manager,notes
     */
    @PostMapping
    @RequestMapping(value = "/updateArchDept",method = RequestMethod.POST)
    public Response updateArchDept(@RequestBody ArchDept archDept){
        commonUtil.recordOperateLog("修改部门分类Id为"+archDept.getArchDeptId()+"的部门分类");
        return  archDeptService.updateArchDept(archDept);
    }
    /**
    *设置为主管
    */
    @PostMapping
    @RequestMapping(value = "/setManager",method = RequestMethod.POST)
    public Response setManager(@RequestBody JSONObject obj){
        int archDeptId=obj.getInteger("archDeptId");
        int staffId=obj.getInteger("staffId");
        String manager=obj.getString("manager");
        String archDeptName=obj.getString("archDeptName");
        commonUtil.recordOperateLog("设置了部门"+archDeptName+"的主管为"+manager);
        return  archDeptService.setManager(archDeptId,staffId,manager,archDeptName);
    }


}
